package spring_learn.a13;


import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

//模拟cglib动态代理的实现
public class A13_2 {


    public static void main(String[] args) {
        Target target=new Target();
        Proxy proxy = new Proxy();
        proxy.setMethodInterceptor(new MethodInterceptor() {
            @Override
            public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
                System.out.println("before");
                Object res = method.invoke(target, objects);
                System.out.println("after");
                return res;
            }
        });
        proxy.save();
        proxy.save(1);
        proxy.save(1L);
    }
}
